#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Maxn=1e5+7;
int n,S1[Maxn],T1[Maxn],S2[Maxn],T2[Maxn],a[Maxn],tag[Maxn],tag1[Maxn];
int Q;
int ret=0;

int main(){
    freopen("good.in","r",stdin);
    freopen("good.out","w",stdout);
    scanf("%d%d",&n,&Q);
    for(int i=1;i<=n;i++) scanf("%1d",&a[i]);

    while(Q--){
        int l,r;
        scanf("%d%d",&l,&r);
        for(int i=l-1;i<=r+1;i++) S1[i]=T1[i]=S2[i]=T2[i]=0,tag[i]=tag1[i]=0;
        int r1=0,r2=0;
        for(int i=l;i<=r;i++){
            S1[i]=S1[i-1]+(a[i]==1);
            T1[i]=T1[i-1]+(a[i]==0);
            if(S1[i]+r1-T1[i]<0 and a[i]==0) r1++,tag[i]=1;
        }
        for(int i=r;i>=l;i--){
            S2[i]=S2[i+1]+(a[i]==1);
            T2[i]=T2[i+1]+(a[i]==0);
            if(S2[i]+r2-T2[i]<0 and a[i]==0) r2++,tag1[i]=1;
        }

        int ans=0;
        for(int i=l;i<=r;i++){
            if(a[i]!=0) continue;
            if(tag[i]||tag1[i-1]) ans++;
        }
        ans+=tag1[r];
        // printf("%d\n",ans);
        ret^=ans;
    }
    printf("%d",ret);

    return 0;
}
/*
10 5
0001001111
1 6
1 10
5 7
4 7
4 6
*/